/**
 * @param {string[]} strs
 * @return {string}
 */
var longestCommonPrefix = function (strs) {
    if (!strs.length) {
        return ''
    }
    let rslt = strs[0]
    for (let i = 1; i < strs.length; i++) {
        let len = Math.max(rslt.length, strs[i].length)
        for (let j = 0; j < len; j++) {
            if (rslt[j] !== strs[i][j]) {
                rslt = rslt.slice(0, j)
                if (rslt === '') {
                    return ''
                }
                break
            }
        }
    }
    return rslt
};

console.log(longestCommonPrefix(["rog", "racecar", "rar"]))